// pages/chooseItem/chooseItem.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    

  },

  handleClick: function (attr) {

    var deviceFlag = attr.currentTarget.dataset.deviceflag;
    if ("paster" === deviceFlag){
      //先登录
      this.loginBtnClick();
    } else if ("hand" === deviceFlag ){
      wx.navigateTo({ url: "../camera/camera" })
    } else if ("showdata" === deviceFlag ){
      wx.navigateTo({ url: "../showdata/showdata" })
    }

  },
  loginBtnClick: function(){
    //获取用户名称和头像      
    //调用应用实例的方法获取全局数据
    var data = {
      "type": "userlogin",
      "num": app.globalData.mobile,
      "password": app.globalData.password
    }
    wx.showLoading({
      title: "验证中...",
      mask: true
    });

    app.func.reqForTiePianLogin(data, function (res) {
      console.info(res);
      if (res.code == "0") {
        console.info(res.message);
        wx.showToast({
          title: res.message
        })
      } else {
        wx.hideLoading();
        //登录成功存储staff
        app.globalData.username = res.vip_info.login_account;
        app.globalData.id = res.vip_info.id;
        //save logininfo
        wx.setStorageSync('username', res.vip_info.login_account);
        wx.setStorageSync('id', res.vip_info.id);
        wx.navigateTo({ url: "../paster/paster" })
      }
    });
  },


})